<!-- 装置激活 -->
<template>
  <div  class="dashboard-editor-container">
    <el-row style="background: #fff; padding: 16px 16px 0;">
    <div style="width:52%;min-width: 1100px">
      <div class="btn topSubmitBtn" style="display:flex;justify-content:flex-end">
        <el-button type="primary" @click="submit()">保存设置</el-button>
      </div>
      <div class="input-item"> 
        <div class="parameType">
          <div class="title">认证中心（建议在厂商配合下配置，非特殊情况不要修改）</div>
          <div class="content top1">
            <div class="certification">
              <el-form label-width="120px">
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="校区编码:">
                    <el-input v-model="deviceForm.SchoolID"  oninput="value=value.replace(/[^0-9]/g,'')" maxlength="16" style="width:280px"></el-input>
                  </el-form-item>
                  <p>必须和管理中心配置编码一一对应</p>
                </el-col>
              </el-form>
            </div>
          </div>
        </div>
        <div class="parameType">
          <div style="display:flex;justify-content:space-between;border-bottom:1px solid #eceff5">
            <div class="title" style="border:none">校区信息（为了更好的为您做好售后服务，请仔细核对您的信息正确性）</div>
            <!-- <div>
              <p style="color:#aaa;font-size:12px;padding-left:50px;" :style="{color:`${this.dayColor || '#aaa'}`}"> {{Days}} 后到期</p>
            </div> -->
          </div>
          <div class="content">
            <div class="information">
              <el-form label-width="120px">
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="所在校区:">
                    <el-input v-model="deviceForm.Campus" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                  <el-form-item label="校区地址:">
                    <el-input v-model="deviceForm.Address" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                  <el-form-item label="校区备注:">
                    <el-input v-model="deviceForm.Descp" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                  <el-form-item label="创建时间:">
                    <el-input v-model="deviceForm.CreateTime" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                  <el-form-item label="联系人:">
                    <el-input v-model="deviceForm.Contact" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                  <el-form-item label="联系电话:">
                    <el-input v-model="deviceForm.Phone" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="8">
                  <el-form-item label="联系邮箱:">
                    <el-input v-model="deviceForm.EMail" disabled class="custom-input"></el-input>
                  </el-form-item>
                </el-col>
                
              </el-form>
            </div>
          </div>
        </div>
      </div>
    </div>
    </el-row>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import { connrequest } from '@/api/firstPage'
import { parseTime, formatTime } from '@/utils/index.js';
export default {
data() {
  return {
    deviceForm:{},
    Days: 0,
    dayColor:'#67C23A',
  }
},
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getData()
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
  },
  methods: {
    async getData() {
      const res = await connrequest('GetDCDInfo')
      let now = new Date().getTime()
      this.Days = res.Data?.ValidTim ? this.dateTrans(res.Data.ValidTime * 1000 - now) : '0天'
      for (const key in res.Data) {
        res.Data['CreateTime'] = parseTime(res.Data['CreateTime'])
        res.Data['Campus'] = res.Data?.PrimArea ? `${res.Data['PrimArea']}-${res.Data['SecondArea']}-${res.Data['SchoolName']}` : ''
        res.Data['MaxRegEmployeeCount'] = res.Data['MaxRegEmployeeCount'] === 0 ? '不控制' : res.Data['MaxRegEmployeeCount']
        res.Data['MaxAICountPerDay'] = res.Data['MaxAICountPerDay'] === 0 ? '不控制' : res.Data['MaxAICountPerDay']
        res.Data['MaxAI40CountPerDay'] = res.Data['MaxAI40CountPerDay'] === 0 ? '无权限' : res.Data['MaxAI40CountPerDay']
        res.Data['MaxEMailCountPerDay'] = res.Data['MaxEMailCountPerDay'] === 0 ? '智能控制' : res.Data['MaxEMailCountPerDay']
      }
      this.deviceForm = res.Data
    },
    dateTrans(date) {
      let computeTime = date / 1000
      let year = Math.floor(computeTime / 86400 / 365);
      computeTime = computeTime % (86400 * 365);
      let month = Math.floor(computeTime / 86400 / 30);
      computeTime = computeTime % (86400 * 30);
      let day = Math.floor(computeTime / 86400);
      computeTime = computeTime  % 86400;
      if(year < 1 && month < 1 && (day <= 30)){
        this.dayColor = '#eec920'
      }
      if(year < 1 && month < 1 && (day <= 7)){
        this.dayColor = '#E6A23C'
      }
      if(year < 1 && month < 1 && (day <= 0)){
        this.dayColor = '#F56C6C'
      }
      return `${year > 0 ? year + '年' : ''}${month > 0 ? month + '个月' : ''}${day}天`;
    },
    async submit(){
      // this.$message.info('该功能还在测试阶段')
      // return
      // let reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
      let character32 = /^[A-Za-z0-9]{1,32}$/
      // if (this.deviceForm.CenterIP === '') {
      //   this.$message.error("认证中心不能为空");
      //   return false;
      // }
      // if (!reg.test(this.deviceForm.CenterIP) && !domainName.test(this.deviceForm.CenterIP)) {
      //   //  www.hunterxyz.com
      //   this.$message.error("认证中心格式错误");
      //   return false;
      // }
      if (this.deviceForm.CorpUUID === '') {
        this.$message.error("企业编码不能为空");
        return false;
      }
      if (!character32.test(this.deviceForm.CorpUUID)) {
        this.$message.error("企业编码格式错误");
        return false;
      }
      const data = {
        Data:{
          ...this.deviceForm
        }
      }
      const res = await connrequest('SetDCDInfo', data)
      if(res.Status.StatusCode === 0) {
        this.$message.success('保存成功')
        this.getData()
        const confirmText = [`修改装置激活信息需要重启设备才能生效。`,`您需要立刻重启设备吗？(设备重启将导致导致域名加速功能短时间失效)`]
        const newDatas = []
          const h = this.$createElement
          for (const i in confirmText) {
            newDatas.push(h('p', null, confirmText[i]))
          }
        this.$confirm('提示', {
          message: h('div', null, newDatas),
          confirmButtonText: '重启设备',
          cancelButtonText: '稍后重启',
          type: 'warning'
        }).then(async () => {
          const data = {
            Data:{
              Action: 'Reboot'
            }
          }
          await connrequest('ExecDeviceMaint', data)
          this.$store.dispatch('user/resetToken').then(() => {
            location.reload()
          })
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入css类 */
// .parmeType {
//   width: 850px;
// }
.custom-input:disabled {
  background-color: #fff !important;
}
.parameType{
  margin: 10px 0;
  padding-bottom: 0;
}
.content {
  width: 900px;
  position: relative;
  margin: 5px 0;
  display: flex;
  flex-wrap: wrap;
  svg{
    font-size: 40px !important;
    margin-right: 20px;
  }
  ::v-deep .certification{
    .el-form-item{
      margin-bottom: 0;
    }
    .el-col{
      width: 1000px;
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      p{
        display:block;
        color: #aaa;
        font-size: 12px;
        padding-left: 20px;
        white-space: nowrap;
      }
    }
  }
  .setUp{
    display: flex;
    align-items: center;
    width: 100%;
    // margin-bottom: 20px;
    flex-grow: 1;
    i{
      margin-right: 20px;
    }
    p{
      font-size: 14px;
      color: red;
    }
  }
  .btn{
    position: absolute;
    right: 50px;
    bottom: 20px;
  }
}
.top1{
  flex-wrap: nowrap;
  // margin-bottom: 20px;
}
::v-deep.el-form-item{
  margin-bottom: 10px;
  label{
    font-weight: 500;
  }
}
</style>